from django.db import models
from base.models import BaseModel


class AccountModel(BaseModel):
    '''
    证
    '''
    model_name = '证'
    model_sign = 'account'

    master_id = models.CharField('主账号', max_length=128, db_index=True, default=None, null=True)
    password = models.CharField('密码', max_length=256, null=True, default='')
    typ = models.CharField('类型', max_length=128, default='')


class HostModel(BaseModel):
    '''
    主机管理
    '''
    model_name = '主机'
    model_sign = 'host'

    name = models.CharField('名称', max_length=64)
    ip = models.CharField('IP地址', max_length=32)

    class Meta:
        db_table = 'host'


class UserModel(BaseModel):
    '''
    用户表
    '''
    model_name = '用户'
    model_sign = 'user'

    ZONE_CNC = 40
    ZONE_CTC = 4
    ZONE_CHOICES = (
        (ZONE_CNC, '网通'),
        (ZONE_CTC, '电信'),
    )

    SITE_LEFT = 1
    SITE_RIGHT = 2
    SITE_CHOICES = (
        (SITE_LEFT, '左'),
        (SITE_RIGHT, '右'),
    )

    ST_ENABLE = '启用'
    ST_DISABLE = '禁用'
    ST_WORK = '工作'
    ST_CHOICES = (
        (ST_ENABLE, '启用'),
        (ST_DISABLE, '禁用'),
        (ST_WORK, '工作'),
    )

    base_fields = ['master_id', 'slave_id', 'zone', 'site', 'name', 'job', 'step', 'level',
            'exp', 'gap', 'bag_money', 'bank_money', 'is_vol', 'bank_grid', 'line', 'cg_pid', 'cga_pid', 'dt_update']

    master_id = models.CharField('主账号', max_length=128, db_index=True, default=None, null=True)
    slave_id = models.CharField('子账号', max_length=128, db_index=True, default=None, null=True)
    zone = models.SmallIntegerField('电信/网通', db_index=True, choices=ZONE_CHOICES, default=None, null=True)
    site = models.SmallIntegerField('左/右', db_index=True, choices=SITE_CHOICES, default=None, null=True)
    password = models.CharField('密码', max_length=256, null=True, default='')
    status = models.CharField('状态', max_length=128, default=ST_DISABLE, choices=ST_CHOICES)
    name = models.CharField('角色名', max_length=128, default=None, null=True)
    job = models.CharField('职业', max_length=128, default=None, null=True)
    level = models.IntegerField('等级', default=0, null=True)
    step = models.IntegerField('阶级', default=-1, null=True)
    exp = models.IntegerField('当前经验', default=0, null=True)
    gap = models.IntegerField('剩余经验', default=0, null=True)
    bag_money = models.IntegerField('背包金额', default=0, null=True)
    bank_money = models.IntegerField('银行金额', default=0, null=True)
    is_vol = models.BooleanField('是否大客户', default=False)
    bank_grid = models.IntegerField('银行格子数', default=20)
    line = models.SmallIntegerField('线路', null=True, default=None)
    is_online = models.BooleanField('是否在线', null=True, default=False)
    cg_pid = models.IntegerField('CG PID', null=True, default=None)
    cga_pid = models.IntegerField('CGA PID', null=True, default=None)
    task = models.CharField('任务', max_length=128, null=True, default='')

    class Meta:
        db_table = 'user'


class SkillModel(BaseModel):
    '''
    技能
    '''
    user = models.ForeignKey(UserModel, on_delete=models.CASCADE)
    name = models.CharField('名称', max_length=128, default='')
    level = models.IntegerField('等级', default=0)
    max_level = models.IntegerField('最高等级', default=0)
    exp = models.IntegerField('当前经验', default=0)
    gap = models.IntegerField('剩余经验', default=0)

    class Meta:
        db_table = 'skill'


class GoodsModel(BaseModel):
    '''
    物品
    '''
    TYP_BANK = 'bank'
    TYP_BODY = 'body'
    TYP_BAG = 'bag'
    TYP_CHOICES = (
        (TYP_BANK, '银行'),
        (TYP_BODY, '身上'),
        (TYP_BAG, '背包'),
    )

    user = models.ForeignKey(UserModel, on_delete=models.CASCADE)
    name = models.CharField('名称', max_length=128, default='')
    typ = models.CharField('类型', max_length=128, choices=TYP_CHOICES)
    sign = models.CharField('标识', max_length=128, default='')
    count = models.IntegerField('数量', default=0)
    level = models.IntegerField('等级', default=0)
    # 用于存储类似物品属性、耐久等信息
    extra = models.TextField('备注信息', null=True, default=None)

    class Meta:
        db_table = 'goods'


class PetModel(BaseModel):
    '''
    宠物
    '''
    TYP_BANK = 'bank'
    TYP_BAG = 'bag'
    TYP_CHOICES = (
        (TYP_BANK, '银行'),
        (TYP_BAG, '背包'),
    )

    user = models.ForeignKey(UserModel, on_delete=models.CASCADE)
    name = models.CharField('名称', max_length=128, default='')
    real_name = models.CharField('真实名称', max_length=128, default='')
    level = models.IntegerField('等级', default=0)
    typ = models.CharField('类型', max_length=128, choices=TYP_CHOICES)
    sign = models.CharField('标识', max_length=128, default='')
    extra = models.TextField('备注信息', null=True, default=None)

    class Meta:
        db_table = 'pet'


class ScriptModel(BaseModel):
    '''
    脚本
    '''
    name = models.CharField('名称', max_length=128, default='')
    path = models.CharField('路径', max_length=256, default='')

    class Meta:
        db_table = 'script'


class SettingModel(BaseModel):
    '''
    配置
    '''
    name = models.CharField('名称', max_length=128, default='')
    path = models.CharField('路径', max_length=256, default='')

    class Meta:
        db_table = 'setting'


class MessageModel(BaseModel):
    '''
    消息
    '''
    TYP_PET = '抓宠'
    TYP_LEVELING = '练级'
    TYP_CHOICES = (
        (TYP_PET, '抓宠'),
        (TYP_LEVELING, '练级'),
    )

    user = models.ForeignKey(UserModel, on_delete=models.CASCADE)
    typ = models.CharField('类型', max_length=128, choices=TYP_CHOICES)
    content = models.TextField('详情')


class DutyModel(BaseModel):
    '''
    当班表
    '''
    user = models.ForeignKey(UserModel, on_delete=models.CASCADE)
    task = models.CharField('当班任务', max_length=64)